package service

import (
	"github.com/go-admin-team/go-admin-core/sdk/service"
	dto2 "tuowei.com/app/other/service/dto"
	"tuowei.com/app/teacher/service/dto"
	service2 "tuowei.com/common/service"
)

type TeacherLogin struct {
	service.Service
}

func (t TeacherLogin) GetMessageCode(sms *service2.AliSms, req *dto.GetMessageCodeRequest) error {
	phone := req.Phone
	//teacher := new(models.SysUser)
	//err := t.Orm.Where("is_auth_app_login = 1").Where("phone = ?", phone).First(teacher).Error
	//if err != nil {
	//	if err == gorm.ErrRecordNotFound {
	//		return errors.New("此电话不存在")
	//	} else {
	//		return err
	//	}
	//}
	//// 检测短信是否发送了
	//redisClient := config.GetRedisClient()
	//key := util.MakeMessageCodeKey("teacher", phone)
	//ttlCmd := redisClient.TTL(key)
	//if ttlCmd.Err() != nil {
	//	xlog.Error(ttlCmd.Err())
	//	return ttlCmd.Err()
	//} else {
	//	remainsTime := ttlCmd.Val()
	//	if remainsTime > 0 {
	//		return errors.New("验证码已经发送,还需" + strconv.Itoa(int(remainsTime.Seconds())) + "秒可继续发送")
	//	}
	//}
	err := sms.CreateClient(&dto2.PhoneCodeReq{Phone: phone}, "teacher")
	return err
}
